package com.wfuhui.modules.store.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wfuhui.common.utils.Query;
import com.wfuhui.common.utils.R;
import com.wfuhui.modules.store.entity.UserGroupEntity;
import com.wfuhui.modules.store.service.UserGroupService;


/**
 * 用户分组
 * 
 * @author xiaotian
 * @email codemax@qq.com
 */
@RestController
@RequestMapping("usergroup")
public class UserGroupController {
	@Autowired
	private UserGroupService userGroupService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("usergroup:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<UserGroupEntity> userGroupList = userGroupService.queryList(query);
		int total = userGroupService.queryTotal(query);
		
		return R.ok().put("rows", userGroupList).put("total", total);
	}
	
	@RequestMapping("/getAll")
	public R getAll(){
		List<UserGroupEntity> userGroupList = userGroupService.queryList(null);
		return R.ok().put("userGroupList", userGroupList);
	}
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("usergroup:info")
	public R info(@PathVariable("id") Integer id){
		UserGroupEntity userGroup = userGroupService.queryObject(id);
		
		return R.ok().put("userGroup", userGroup);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("usergroup:save")
	public R save(@RequestBody UserGroupEntity userGroup){
		userGroupService.save(userGroup);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("usergroup:update")
	public R update(@RequestBody UserGroupEntity userGroup){
		userGroupService.update(userGroup);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("usergroup:delete")
	public R delete(@RequestBody Integer[] ids){
		userGroupService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
